<template>
  <div class="wrapper" ref="wrapper">
    <slot></slot>
  </div>
</template>

<script>
import BScroll from "better-scroll";
export default {
  name: "Scroller",
  props: {
    handleToScroller: {
      type: Function,
      default: function () {},
    },
    hanleToTouchEnd: {
      type: Function,
      default: function () {},
    },
  },
  mounted() {
    var scroll = new BScroll(this.$refs.wrapper, {
      // tap: true,
      probeType: 1,
      click: true,
      observeDOM: true,
    });
    scroll.on("scroll", (pos) => {
        this.handleToScroller(pos);
    });
    scroll.on("touchEnd", (pos) => {
      this.hanleToTouchEnd(pos);
    });
    this.scroll = scroll
  },
  methods:{
    toScrollTop(y){
      this.scroll.scrollTo(0,y);
    }
  }
};
</script>

<style scoped>
.wrapper {
  height: 100%;
}
</style>